Skip to content

Example vite web app #2967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Example vite web app #2967

wants to merge 4 commits into from

Conversation

sdcooke
Copy link

@sdcooke sdcooke commented Feb 17, 2025

Example web app using vite/esbuild. Getting the configuration to work in this monorepo was a little awkward, so there might be some unnecessary code here but I've tried to keep it as minimal as possible.

Reverting 6443ac2 causes the error reported in #2960 to show when running yarn dev in this app's directory.

The app itself has a simple page with 2 skia examples using reanimated shared values, neither of which works (possibly related to #2943).

@sdcooke
Copy link
Author

sdcooke commented Feb 17, 2025

I have signed the CLA!

@wcandillon
Copy link
Contributor

@sdcooke my apologies for seeing this only now. This looks very interesting, let me have a look now.

@sdcooke
Copy link
Author

sdcooke commented Jun 21, 2025

@wcandillon no worries - I'm now on the latest version of react-native-skia and everything (including animations) seems to be working so I don't think there's any investigation to be done.

This example app could still potentially be useful for future testing though.

@wcandillon
Copy link
Contributor

I like the idea but I couldn't run the example unfortunately:

✘ [ERROR] The JSX syntax extension is not currently enabled

    node_modules/react-native-reanimated/lib/module/component/PerformanceMonitor.js:93:9:
      93 │   return <View style={styles.container}>
         ╵          ^

@sdcooke
Copy link
Author

sdcooke commented Jun 21, 2025

Ah yes this is the problem I've experienced in my app. Since 3.17.2 reanimated has included JSX in .js files and I haven't worked out how to get vite to handle them correctly. I'll see if I can fix it on this branch, in my app I've had to pin reanimated to 3.17.1 which obviously isn't an option here!

@sdcooke
Copy link
Author

sdcooke commented Jun 22, 2025

I've pushed a workaround for the JSX in .js files issue - it only works in dev, not build. Despite skia and the animations working well in my app, they don't seem to be working in this example.

I'm going to have to come back to this another time, but if you're interested you should be able to run yarn dev in the apps/vite-web directory and at least see the test page!

@JacobDel
Copy link

I got the build working with this vite.config.js file.
It's not clean, but it's a start.
packages:

"vite-plugin-react-native-web", had to make a fork: https://github.com/JacobDel/vite-plugin-react-native-web/tree/local
"vite-plugin-babel": "^1.3.2",
"vite-plugin-commonjs": "^0.10.4",
"@vitejs/plugin-react": "^4.5.2",
import {defineConfig} from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import reactNativeWeb from 'vite-plugin-react-native-web';
import babel from 'vite-plugin-babel';
import commonjs from 'vite-plugin-commonjs';

const development = process.env.NODE_ENV === 'development';

export default defineConfig({
  clearScreen: true,
  plugins: [
    react({
      // babel will only handle src, not node_modules
    }),
    babel({
      babelConfig: {
        configFile: false,
        babelrc: false,
        presets: ['@babel/preset-react', '@babel/preset-flow'],
        plugins: [
          '@babel/plugin-transform-export-namespace-from', // https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started/#web
          'react-native-reanimated/plugin',
        ],
      },
    }),

    ...(development
      ? []
      : [
          babel({
            include: [/node_modules\/(react-native|@react-native)/],
            babelConfig: {
              plugins: [
                [
                  // this is a fix for reanimated not working in production
                  '@babel/plugin-transform-modules-commonjs',
                  {
                    strict: false,
                    strictMode: false, // prevent "use strict" injections
                    allowTopLevelThis: true, // dont rewrite global `this` -> `undefined`
                  },
                ],
              ],
            },
          }),
        ]),
    reactNativeWeb({transformJsx: false}),
    commonjs({
      transformMixedEsModules: true,
    }),
  ],
  server: {
    port: 3000,
  },
  build: {
    outDir: 'build',
  },
  resolve: {
    alias: [
      {
        find: 'qdzqdzqdzqdzdqd',
        replacement: 'react-native/Libraries/Image/AssetRegistry', // had to hardcode the original path to giberish so that the next part won't change it
      },
      {find: 'react-native', replacement: 'react-native-web'},
    ],
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants